IE9 FF CHROME
<button type="button" id="button" class="btn" name="button">click</button>
<script type="text/javascript">
var oBtn=document.getElementById("button");
oBtn.onclick=function(event){
console.log(event.target) // <button id="button" class="btn" name="button" type="button">
console.log(event.srcElement.className) //btn
}
</script>
IE6-8
<button type="button" id="button" class="btn" name="button">click</button>
<script type="text/javascript">
var oBtn=document.getElementById("button");
oBtn.onclick=function(event){
var event=window.event;
console.log(event.srcElement) // <button id="button" class="btn" name="button" type="button">
console.log(event.srcElement.className) //btn
}
</script>
兼容
<button type="button" id="button" class="btn" name="button">click</button>
<script type="text/javascript">
var oBtn=document.getElementById("button");
oBtn.onclick=function(event){
var event=event || window.event;
obj = event.srcElement ? event.srcElement : event.target;
console.log(obj.id)
}
</script>
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。